package com.wgchao.amc.repository.base;

import com.wgchao.amc.entity.base.SysBaseUg;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @Description  
 * @Author  Wgchao
 * @Date 2019-10-28 
 */
@Repository
public interface SysBaseUgRepository extends JpaRepository<SysBaseUg, Long>, JpaSpecificationExecutor<SysBaseUg> {

    List<SysBaseUg> findAllByUserId(Long userId);

    List<SysBaseUg> findAllByUserIdAndDelIsFalse(Long userId);

    SysBaseUg findFirstByUserIdAndGroupId(Long userId, Long groupId);

    SysBaseUg findFirstByUserIdAndGroupIdAndDelIsFalse(Long userId, Long groupId);

    @Modifying
    @Query("update SysBaseUg set del = true , delTime= ?1 where userId = ?2")
    void updateUGToDel(Date time, Long userId);
}
